/**
 * 
 */
package controller.auth;

import model.MAuthority;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.interf.IAuthority;

import common.interf.IErrorHandle;

/**
 * @author 鄢倩
 * 2012-12-15
 */
@Controller
@RequestMapping("/auth")
public class AuthorityEditController {
	
	@Autowired
	private IAuthority auth;
	@Autowired
	private IErrorHandle errorHandle;
	

	@RequestMapping("/find_all_authority.htm")
	@ResponseBody
	public String findAll() {
		String s = "";
		try {
			s = auth.getAllAuthorities(0, 0);
			System.out.println(s);
		} catch (Exception e) {
			System.out.println("method : findAll exception");
			errorHandle.handleErr(e);
		}
		return s;
	}
	
	@RequestMapping("/del_authority.htm")
	@ResponseBody
	public String delAuthority(MAuthority model){
		String s = "";
		try {
			//通过
			 s = auth.delAuthority(model.getAuthorityName());
			System.out.println(s);
		} catch (Exception e) {
			System.out.println("methods : findGroups exception");
			errorHandle.handleErr(e);
		}
		return s;
	}
	
	@RequestMapping("/add_authority.htm")
	@ResponseBody
	public String addAuthority(MAuthority model){
		String s = "";
		try {
			s = auth.addAuthority(model);
		} catch (Exception e) {
			System.out.println("method : addAuth exception");
			errorHandle.handleErr(e);
		}
		return s;
	}
	
	@RequestMapping("/batchSave_authority.htm")
	@ResponseBody
	public String batch(MAuthority model) {
		String s = "";
		try {
			s = auth.batchUpdateAuthority(model.getDatas());
		} catch (Exception e) {
			System.out.println("method : batchSaveAuth exception ");
			errorHandle.handleErr(e);
		}
		return s;
	}
	
}
